package com.massfords.jaxb;

import java.util.Set;

import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JMethod;
import com.sun.codemodel.JMod;
import com.sun.codemodel.JPackage;
import com.sun.tools.xjc.outline.ClassOutline;
import com.sun.tools.xjc.outline.Outline;

/**
 * Creates the traverser interface. A traverse method is added for each of the generated beans.
 * 
 * @author markford
 */
public class CreateTraverserInterface extends CodeCreator {
    
    private JDefinedClass mVisitor;

    public CreateTraverserInterface(JDefinedClass aVisitor, Outline aOutline, JPackage aPackage) {
        super(aOutline, aPackage);
        mVisitor = aVisitor;
    }

    @Override
    protected void run(Set<ClassOutline> aClasses) {
        setOutput(getOutline().getClassFactory().createInterface(getPackage(), "Traverser", null));
        for (ClassOutline classOutline : aClasses) {
            // add the bean to the traverser
            JMethod traverseMethod = getOutput().method(JMod.PUBLIC, void.class, "traverse");
            traverseMethod.param(classOutline.implClass, "aBean");
            traverseMethod.param(mVisitor, "aVisitor");
        }
    }
}
